<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>应用接入</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="">

            <div class="layui-form-item">
                <label class="layui-form-label required">应用名</label>
                <div class="layui-input-inline" style="width:250px">
                    <input type="text" name="appname"  lay-verify="required" lay-reqtext="不能为空"  placeholder="不能为空" value="" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux"><span style="color:red">注:不能用中文，请按照以往应用格式创建应用名</span></div>
            </div>
            
            <div class="layui-form-item" pane="">
                <label class="layui-form-label">接入类型</label>
                <div class="layui-input-inline" style="width:200px">
                    <input type="radio" name="jrtype" value="ecs" lay-filter="jrtype" title="ecs" checked="">
                    <input type="radio" name="jrtype" value="k8s" lay-filter="jrtype" title="k8s">
                </div>
            </div>

            <div class="layui-form-item layui-form-text"  id="EcsTpl">
                <label class="layui-form-label required">IP端口</label>
                <div class="layui-input-block">
                    <textarea name="serverip" style="height:147px" class="layui-textarea" placeholder="请输入ip和端口，一行一个，参考格式:&#13;&#10;192.168.1.1:8080&#13;&#10;192.168.1.2:8080"></textarea>
                </div>
            </div>

            <div class="layui-form-item" id="K8sTpl">
                <div class="layui-inline">
                    <label class="layui-form-label">k8s集群</label>
                    <div class="layui-input-inline" style="width:130px">
                        <input type="text" name="clusterid" autocomplete="off" class="layui-input">
                      <!--
                      <select name="clusterid" lay-filter="clusterid">
                        <option value="" selected=""></option>
                        <option value="cluster1">cluster1</option>
                        <option value="cluster2">cluster2</option>			
                      </select>
                      -->
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">命名空间</label>
                    <div class="layui-input-inline" style="width:130px">
                        <input type="text" name="namespace" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">deployment</label>
                    <div class="layui-input-inline" style="width:130px">
                        <input type="text" name="deployment" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">备注</label>
                <div class="layui-input-block">
                    <input type="text" name="remarks" autocomplete="off" class="layui-input">
                    <!-- <textarea name="remarks" style="height:147px" class="layui-textarea" lay-verify=""></textarea> -->
                </div>
            </div>  
                         
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        $("#EcsTpl").show();
        $("#K8sTpl").hide();
        form.on('radio(jrtype)', function (data) { 
            if(data.value == 'ecs'){
              $("#EcsTpl").show();
              $("#K8sTpl").hide();
            }else{
              $("#EcsTpl").hide();
              $("#K8sTpl").show();      
            }  
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
                data.field.appname = data.field.appname.replace(/^\s*|\s*$/g,""); //替换空格
                data.field.serverip = data.field.serverip.replace(/server|;/g,"");
                data.field.serverip = data.field.serverip.replace(/：/g,":");
                data.field.serverip = data.field.serverip.replace(/，|\r|\n/g,",");
                data.field.serverip = data.field.serverip.replace(/^\s*|\s*$/g,"");
                data.field.serverip = data.field.serverip.replace(/\s/g,"");
                
					      console.log(data.field);
			          layer.confirm('确定添加?', {icon: 3, title:'提示',yes: function(index){
                     var index2 = layer.load(0, {shade: false});
                     layer.msg('稍等片刻');
                     $.ajax({
                       url: "/xwaf/app/v1/Add",
                       type: "post",
                       data: JSON.stringify(data.field),
                       dataType: "json",
                       success: function (resp) {
                                layer.close(index2);
                                 if(resp.code == 0){
                                    layer.msg('添加成功', {icon: 1});
									                  //window.location.reload();
                                 }else{
                                    layer.msg(resp.msg,{icon:2});
                                 }
                        }
                      });		  	  
                  },
                  cancel: function(index, layero){ 
                    layer.close(index);
                    layer.close(index2);
		                console.log("不操作");
                  } 
                });
              return false;
        });

    });
</script>
</body>
</html>